﻿
using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_Project_DangqianXiangmu : TeamBBasePage
{
    private string dataTime = DateTime.Today.ToString("yyyy-MM-dd");
    public Maticsoft.BLL.Order orderbll = new Maticsoft.BLL.Order();
    public Maticsoft.BLL.orderdetail orderdetailbll = new Maticsoft.BLL.orderdetail();
    public string style = "";
    public string style1 = "";
    public string style2 = "";
    public string style3 = "";
    public Maticsoft.BLL.Team teams = new Maticsoft.BLL.Team();

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.getDangqian();
    }

    private void delProject(int id)
    {
        bool flag = false;
        if ((this.orderbll.GetModelList("Team_id=" + id + " and State='pay'").Count > 0) || (this.orderdetailbll.GetModelList("Teamid=" + id).Count > 0))
        {
            flag = true;
        }
        else
        {
            flag = false;
        }
        if (flag)
        {
            this.SetError("项目已成交，不能删除,删除失败");
        }
        else
        {
            this.teams.Delete(id);
            base.SetSuccess("删除成功");
        }
    }

    private void getDangqian()
    {
        int num;
        this.Literal1.Text = "<tr ><th width='40'>ID</th><th width='400'>项目名称</th><th width='80' nowrap>类别</th><th width='100'>日期</th><th width='50'>成交</th><th width='60' nowrap>价格</th><th width='140'>操作</th></tr>";
        StringBuilder builder = new StringBuilder();
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        Maticsoft.Model.Category model = new Maticsoft.Model.Category();
        List<Maticsoft.Model.Team> list = new List<Maticsoft.Model.Team>();
        list = this.teams.SearchTeam(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, "*", "order by Sort_order desc,End_time desc", this.sqlWhere, out num);
        this.AspNetPager1.RecordCount = num;
        this.pages = this.AspNetPager1.CurrentPageIndex;
        int num2 = 0;
        foreach (Maticsoft.Model.Team team in list)
        {
            if ((num2 % 2) != 0)
            {
                builder.Append("<tr>");
            }
            else
            {
                builder.Append("<tr class='alt'>");
            }
            num2++;
            builder.Append("<td>" + team.Id + "</a></td>");
            string str = team.Team_type;
            if (str != null)
            {
                if (!(str == "normal"))
                {
                    if (str == "seconds")
                    {
                        goto Label_0181;
                    }
                    if (str == "goods")
                    {
                        goto Label_01CF;
                    }
                }
                else
                {
                    builder.Append(string.Concat(new object[] { "<td>[团购]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
                }
            }
            goto Label_021F;
        Label_0181: ;
            builder.Append(string.Concat(new object[] { "<td>[秒杀]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
            goto Label_021F;
        Label_01CF: ;
            builder.Append(string.Concat(new object[] { "<td>[热销]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
        Label_021F:
            if ((team.Group_id == 0) && (team.City_id == 0))
            {
                builder.Append("<td nowrap>全部城市<br/></td>");
            }
            else
            {
                builder.Append("<td nowrap>");
                model = category.GetModel(team.City_id);
                if (model != null)
                {
                    builder.Append(model.Name);
                }
                else
                {
                    builder.Append("全部城市");
                }
                builder.Append("<br/>");
                model = category.GetModel(team.Group_id);
                if (model != null)
                {
                    builder.Append(model.Name);
                }
                else
                {
                    builder.Append("&nbsp;");
                }
                builder.Append("</td>");
            }
            builder.Append(string.Concat(new object[] { "<td nowrap>", team.Begin_time, "<br/>", team.End_time, "</td>" }));
            builder.Append(string.Concat(new object[] { "<td nowrap>", team.Now_number, "/", team.Min_number, "</td>" }));
            builder.Append(string.Concat(new object[] { "<td nowrap><span class='money'>\x00a5</span>", team.Market_price, "<br/><span class='money'>\x00a5</span>", team.Team_price, "</td>" }));
            builder.Append("<td class='op' nowrap>");
            builder.Append("<a class='ajaxlink' href='/ajax/manage.aspx?action=teamdetail&id=" + team.Id + "'>详情</a>｜");
            builder.Append("<a href='Project_BianjiXiangmu.aspx?id=" + team.Id + "'>编辑</a>｜");
            builder.Append(string.Concat(new object[] { "<a href='Project_DangqianXiangmu.aspx?remove=", team.Id, "&pageIndex=", this.AspNetPager1.CurrentPageIndex, "&where=", DESEncrypt.Encrypt(this.sqlWhere, "type"), "'  ask='确定删除本项目吗？' >删除</a>" }));
            builder.Append("</td>");
            builder.Append("</tr>");
        }
        this.Literal2.Text = builder.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "program";
        if (base.Request.QueryString["remove"] != null)
        {
            this.delProject(int.Parse(base.Request.QueryString["remove"].ToString()));
            if ((base.Request.QueryString["pageIndex"] != null) && (base.Request.QueryString["pageIndex"].ToString() != ""))
            {
                this.AspNetPager1.CurrentPageIndex = Convert.ToInt32(base.Request.QueryString["pageIndex"].ToString());
            }
            if ((base.Request.QueryString["where"] != null) && (base.Request.QueryString["where"].ToString() != ""))
            {
                this.sqlWhere = DESEncrypt.Decrypt(base.Request.QueryString["where"].ToString(), "type");
            }
        }
        if (base.Request.QueryString["team_type"] == null)
        {
            this.style = "current";
        }
        else
        {
            string str = base.Request.QueryString["team_type"].ToString();
            if (str != null)
            {
                if (!(str == "normal"))
                {
                    if (str == "seconds")
                    {
                        this.style2 = "current";
                    }
                    else if (str == "goods")
                    {
                        this.style3 = "current";
                    }
                }
                else
                {
                    this.style1 = "current";
                }
            }
            this.sqlWhere = "End_time >=GetDate()  and Begin_time <=GetDate() and  Team_type='" + base.Request.QueryString["team_type"].ToString().Replace("'", "''") + "' ";
        }
        this.getDangqian();
    }

    public int pages
    {
        get
        {
            if (this.ViewState["pages"] != null)
            {
                return Convert.ToInt32(this.ViewState["pages"].ToString());
            }
            return 1;
        }
        set
        {
            this.ViewState["pages"] = value;
        }
    }

    public string sqlWhere
    {
        get
        {
            if (this.ViewState["sqlWhere"] != null)
            {
                return this.ViewState["sqlWhere"].ToString();
            }
            return " End_time >=GetDate() and Begin_time <=GetDate() ";
        }
        set
        {
            this.ViewState["sqlWhere"] = value;
        }
    }
}


